﻿using System;
using System.Linq;
using MS.InformationManagement.Core.Support;
using MS.InformationManagement.DAL.RecordCenter;

namespace MS.InformationManagement.BLL.TRD
{
    public class DisableTRDItemCommand : IBaseCommand
    {
        #region [Private Fields]

        private int? _Id;

        private DataContext _DataContext;

        private ItemTRD _Entity;

        #endregion

        #region [Constructor]

        public DisableTRDItemCommand(int? id, DataContext dataContext)
        {
            _Id = id;
            _DataContext = dataContext;
        }

        #endregion

        #region [IBaseCommand Members]

        public void Execute()
        {
            _Entity = _DataContext.ConfiguraciónTablaDeRetenciónDocumental.SingleOrDefault(item => item.Id.Equals(_Id));
            if (_Entity == default(ItemTRD)) { throw new Exception(string.Format("No existe un item en la lista de configuración de tablas de retención documental con el id {0}", _Id)); }
            _Entity.Activo = false;
            _DataContext.SubmitChanges();
        }

        public void Undo()
        {
            _Entity.Activo = true;
            _DataContext.SubmitChanges();
        }

        #endregion
    }
}
